<template>
  <div id="jobCheckTopSearch">
    <h1 class="con-right-title">
      作业内容审核
    </h1>
    <div class="search-box">
      <el-form
        ref="ruleForm"
        :inline="true"
        :model="formInline"
        class="demo-form-inline"
      >
        <el-form-item label="人审结果" prop="checkStatu">
          <el-select v-model="formInline.checkStatu" clearable>
            <el-option
              v-for="item in checkStatuList"
              :key="item.dictValue"
              :label="item.dictLabel"
              :value="item.dictValue"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="机审结果" prop="machineStatu">
          <el-select v-model="formInline.machineStatu" clearable>
            <el-option
              v-for="item in machineStatuList"
              :key="item.dictValue"
              :label="item.dictLabel"
              :value="item.dictValue"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="作业码" prop="identCode">
          <el-input
            clearable
            v-model.trim="formInline.identCode"
            placeholder="输入作业码搜索"
          ></el-input>
        </el-form-item>
        <el-form-item label="作业性质" prop="courseType">
          <el-select v-model="formInline.courseType" clearable>
            <el-option
              v-for="item in courseTypeList"
              :key="item.dictValue"
              :label="item.dictLabel"
              :value="item.dictValue"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="课程名称" prop="courseTitle">
          <el-input
            clearable
            v-model="formInline.courseTitle"
            placeholder="输入课程名称搜索"
          ></el-input>
        </el-form-item>
        <el-form-item label="选择学院" prop="categoryId">
          <el-select v-model="formInline.categoryId" placeholder="" clearable>
            <el-option
              v-for="item in collegeList"
              :key="item.dictValue"
              :label="item.dictLabel"
              :value="item.dictValue"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="排序规则" prop="order">
          <el-select v-model="formInline.order">
            <el-option
              v-for="(item, index) in orderList"
              :key="index + item.dictValue"
              :label="item.dictLabel"
              :value="item.dictValue"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="作业类型" prop="jobType">
          <el-select v-model="formInline.jobType" clearable>
            <el-option
              v-for="item in jobTypeList"
              :key="item.dictValue"
              :label="item.dictLabel"
              :value="item.dictValue"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="作业标题查询" prop="taskTitle">
          <el-input
            clearable
            v-model="formInline.taskTitle"
            placeholder="输入作业标题搜索"
          ></el-input>
        </el-form-item>
        <el-form-item label="用户搜索" prop="userValue">
          <el-input
            v-model="formInline.userValue"
            placeholder="请输入相应的搜索内容"
          >
            <el-select
              slot="prepend"
              v-model="formInline.userType"
              placeholder="请选择"
            >
              <el-option label="大鹏号" value="DAPENGACCOUNT"></el-option>
            </el-select>
          </el-input>
        </el-form-item>
        <el-form-item prop="timeType">
          <el-select v-model="formInline.timeType" placeholder="作业发布时间">
            <el-option
              v-for="(item, index) in timeTypeList"
              :key="index"
              :label="item.dictLabel"
              :value="item.dictValue"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item prop="createTime">
          <el-date-picker
            v-model="formInline.createTime"
            type="datetimerange"
            range-separator="至"
            start-placeholder="开始时间"
            end-placeholder="结束时间"
            value-format="yyyy-MM-dd HH:mm:ss"
          >
          </el-date-picker>
        </el-form-item>
        <el-form-item label="时间线" prop="timeLine">
          <el-select v-model="formInline.timeLine">
            <el-option
              v-for="item in timeLineList"
              :key="item.dictValue"
              :label="item.dictLabel"
              :value="item.dictValue"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="审核人" prop="checkUserId">
          <el-select v-model="formInline.checkUserId" clearable filterable>
            <el-option
              v-for="(item, index) in checkUserIdList"
              :key="'item' + index"
              :label="item.nickname"
              :value="item.dapengUserId"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="用户属性" prop="userAttribute">
          <el-select v-model="formInline.userAttribute" clearable>
            <el-option
              v-for="item in userAttList"
              :key="item.dictValue"
              :label="item.dictLabel"
              :value="item.dictValue"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item class="s-btn">
          <el-button
            type="success"
            icon="el-icon-search"
            @click="toSearch('ruleForm')"
          >
            查询
          </el-button>
          <el-button type="success" plain @click="reset">
            重置
          </el-button>
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>

<script>
import { sysNormalDisable } from '@utils/dictionariesFunc'
import { getDpNum } from '@/api/system/user'
export default {
  name: 'jobCheckTopSearch',
  msg: '作业内容审核-顶部搜索',
  props: {
    formInline: {
      type: Object,
      default: function() {
        return {
          categoryId: '', // 选择学院
          checkStatu: '', // 人审结果
          machineStatu: '', // 机审结果
          identCode: '', // 作业码
          courseType: '', // 作业性质
          courseTitle: '', // 课程名称
          order: '', // 排序规则
          jobType: '', // 作业类型作业标题
          taskTitle: '', // 作业标题
          timeType: '', // 时间
          timeLine: '', // 时间线
          checkUserId: '', // 审核人
          userAttribute: '', // 用户属性
          userValue: '',
          userType: 'DAPENGACCOUNT',
          createTime: []
        }
      }
    }
  },
  data() {
    return {
      checkStatuList: [
        // 人审结果
        { dictLabel: '全部', dictValue: '' }
      ],
      machineStatuList: [
        // 机审结果
        { dictLabel: '全部', dictValue: '' }
      ],
      courseTypeList: [
        // 作业性质
        { dictLabel: '全部', dictValue: '' }
      ],
      // 审核人
      checkUserIdList: [{ nickname: '全部', dapengUserId: '' }],
      userAttList: [{ dictLabel: '全部', dictValue: '' }], // 用户属性
      orderList: [],
      jobTypeList: [
        // 作业类型
        { dictLabel: '全部', dictValue: '' }
      ],
      timeTypeList: [],
      // 时间线
      timeLineList: [{ dictLabel: '全部', dictValue: '' }],
      collegeList: [
        // 学院
        { dictLabel: '全部学院', dictValue: '' }
      ]
    }
  },
  mounted() {
    this.getStatusList()
    this.getCheckUser()
  },
  methods: {
    /* 获取数据状态 */
    async getStatusList() {
      // 人审结果
      let data = await sysNormalDisable('sys_check_statu', 'personStatus')
      this.checkStatuList = this.checkStatuList.concat(data)
      // 机审结果
      let machine = await sysNormalDisable('sys_machine_statu', 'machineStatus')
      this.machineStatuList = this.machineStatuList.concat(machine)
      // 时间线
      let timeLineList = await sysNormalDisable('sys_jobwork_time')
      this.timeLineList = timeLineList.concat(this.timeLineList)
      // 作业类型
      let jobTypeList = await sysNormalDisable('sys_task_type')
      this.jobTypeList = this.jobTypeList.concat(jobTypeList)
      // 作业性质
      let courseTypeList = await sysNormalDisable('sys_home_course_type')
      this.courseTypeList = this.courseTypeList.concat(courseTypeList)
      // 排序规则
      let orderList = await sysNormalDisable('sys_home_content_audit_sort')
      orderList.map((item) => {
        if (item.dictLabel === '机审时间正序') {
          item.dictValue = 'job_submit_time ASC2'
        }
        if (item.dictLabel === '机审时间倒序') {
          item.dictValue = 'job_submit_time DESC2'
        }
      })
      this.orderList = orderList
      // 时间类型
      let timeTypeList = await sysNormalDisable('home_content_type')
      timeTypeList.map((item) => {
        if (item.dictLabel === '机审时间') {
          item.dictValue = 'submitTime2'
        }
      })
      this.timeTypeList = timeTypeList
      // 用户属性
      let UserAttr = await sysNormalDisable(
        'comment_user_attributes',
        'checkUserAttr'
      )
      this.userAttList = this.userAttList.concat(UserAttr)
      // 学院
      let collegeList = await sysNormalDisable('sys_college', 'collegeType')
      this.collegeList = this.collegeList.concat(collegeList)
      this.setDefaultValue()
      //触发列表获取权限
      this.$emit('toSearch')
    },
    /*设置默认数据*/
    setDefaultValue() {
      this.formInline.timeLine = this.timeLineList[0].dictValue
      this.formInline.order = this.orderList[0].dictValue
      this.formInline.timeType = this.timeTypeList[0].dictValue
    },
    getCheckUser() {
      getDpNum({ type: 'OPERATORS' }, (response) => {
        this.checkUserIdList = this.checkUserIdList.concat(response)
      })
    },
    /* 搜索 */
    toSearch(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          this.$emit('toSearch')
        } else {
          return false
        }
      })
    },
    /* 重置 */
    reset() {
      this.$refs['ruleForm'].resetFields()
      //设置默认数据
      this.setDefaultValue()
    }
  },
  watch: {
    'formInline.createTime': {
      handler(newVal, oldVal) {
        if (newVal && newVal.length > 1) {
          this.formInline.startTime = newVal[0]
          this.formInline.endTime = newVal[1]
        } else {
          this.formInline.startTime = ''
          this.formInline.endTime = ''
        }
      },
      deep: true
    }
  }
}
</script>

<style lang="less">
#jobCheckTopSearch {
  width: 1634px;
  .el-input {
    &.el-input--suffix {
      width: 182px !important;
    }
  }

  label.el-form-item__label {
    width: 100px !important;
  }
}
</style>
